package com.guoguo.service.impl;

import com.github.pagehelper.PageHelper;
import com.guoguo.base.PageBean;
import com.guoguo.entity.Purview;
import com.guoguo.mapper.PurviewMapper;
import com.guoguo.service.IPurviewService;
import com.guoguo.utils.AuthorityValidateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/8/18 0018.
 */
@Service
public class PurviewServiceImpl implements IPurviewService {


    @Autowired
    private PurviewMapper purviewMapper;

    @Override
    public List<Purview> getPurviewList(Boolean status) {
        return purviewMapper.getPurviewList(status);
    }
    @Override
    public PageBean<Purview> selectPurviewList(int pageNumber, int pageSize) {
        PageHelper.startPage(pageNumber,pageSize);

        return new PageBean<Purview>(purviewMapper.selectPurviewList());
    }

    @Override
    public Purview selectByPrimaryKey(String purviewId) {
        return purviewMapper.selectByPrimaryKey(purviewId);
    }

    @Override
    public Purview addPurview(String purviewId, String purviewName, String purviewDescription, String url, String permission, Boolean status) {
        //添加修改
//        String permission= AuthorityValidateUtils.createAuth(String permission,)
        Purview purview=purviewMapper.selectByPrimaryKey(purviewId);
        if(purview==null){
            purview=new Purview(purviewId,purviewName,purviewDescription,url, permission, status);
return purviewMapper.insertSelective(purview);
        }
        purview.setPurviewId(purviewId);
        purview.setPurviewName(purviewName);
        purview.setPurviewDescription(purviewDescription);
        purview.setUrl(url);
        purview.setPermission(permission);
        purview.setStatus(true);
        purview.setCreateTime(new Date());
        return purviewMapper.updateByPrimaryKeySelective(purview);
    }
}

